/*
 * Copyright ${.now?string("yyyy")} the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ${packageName}.impl;

import ${packageName}.I${moduleName?cap_first};
import ${packageName}.I${moduleName?cap_first}Config;
import ${packageName}.annotation.${moduleName?cap_first}Conf;
import net.ymate.platform.core.configuration.IConfigReader;
import net.ymate.platform.core.module.IModuleConfigurer;

/**
 * Default${moduleName?cap_first}Config generated By ModuleMojo on ${.now?string("yyyy/MM/dd HH:mm")}
 *
 * @author YMP (https://www.ymate.net/)
 */
public final class Default${moduleName?cap_first}Config implements I${moduleName?cap_first}Config {

    private boolean enabled = true;

    private boolean initialized;

    public static Default${moduleName?cap_first}Config defaultConfig() {
        return builder().build();
    }

    public static Default${moduleName?cap_first}Config create(IModuleConfigurer moduleConfigurer) {
        return new Default${moduleName?cap_first}Config(null, moduleConfigurer);
    }

    public static Default${moduleName?cap_first}Config create(Class<?> mainClass, IModuleConfigurer moduleConfigurer) {
        return new Default${moduleName?cap_first}Config(mainClass, moduleConfigurer);
    }

    public static Builder builder() {
        return new Builder();
    }

    private Default${moduleName?cap_first}Config() {
    }

    private Default${moduleName?cap_first}Config(Class<?> mainClass, IModuleConfigurer moduleConfigurer) {
        IConfigReader configReader = moduleConfigurer.getConfigReader();
        //
        ${moduleName?cap_first}Conf confAnn = mainClass == null ? null : mainClass.getAnnotation(${moduleName?cap_first}Conf.class);
        //
        enabled = configReader.getBoolean(ENABLED, confAnn == null || confAnn.enabled() );
        //
        // TODO What to do?
    }

    @Override
    public void initialize(I${moduleName?cap_first} owner) throws Exception {
        if (!initialized) {
            if (enabled) {
                // TODO What to do?
            }
            initialized = true;
        }
    }

    @Override
    public boolean isInitialized() {
        return initialized;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        if (!initialized) {
            this.enabled = enabled;
        }
    }

    public static final class Builder {

        private final Default${moduleName?cap_first}Config config = new Default${moduleName?cap_first}Config();

        private Builder() {
        }

        public Builder enabled(boolean enabled) {
            config.setEnabled(enabled);
            return this;
        }

        public Default${moduleName?cap_first}Config build() {
            return config;
        }
    }
}